{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#Building an image retrieval system with deep features\n", "\n", "\n", "#Fire up GraphLab Create" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "A newer version of GraphLab Create (v1.7.1) is available! Your current version is v1.6.1.\n", "\n", "You can use pip to upgrade the graphlab-create package. For more information see https://dato.com/products/create/upgrade.\n" ] } ], "source": [ "import graphlab" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#Load the CIFAR-10 dataset\n", "\n", "We will use a popular benchmark dataset in computer vision called CIFAR-10. \n", "\n", "(We've reduced the data to just 4 categories = {'cat','bird','automobile','dog'}.)\n", "\n", "This dataset is already split into a training set and test set. In this simple retrieval example, there is no notion of \"testing\", so we will only use the training data." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[INFO] This non-commercial license of GraphLab Create is assigned to danielbenitezr@yahoo.com and will expire on September 27, 2016. For commercial licensing options, visit https://dato.com/buy/.\n", "\n", "[INFO] Start server at: ipc:///tmp/graphlab_server-7627 - Server binary: /home/balrog/anaconda/lib/python2.7/site-packages/graphlab/unity_server - Server log: /tmp/graphlab_server_1450965281.log\n", "[INFO] GraphLab Server Version: 1.6.1\n" ] } ], "source": [ "image_train = graphlab.SFrame('image_train_data/')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#Computing deep features for our images\n", "\n", "The two lines below allow us to compute deep features. This computation takes a little while, so we have already computed them and saved the results as a column in the data you loaded. \n", "\n", "(Note that if you would like to compute such deep features and have a GPU on your machine, you should use the GPU enabled GraphLab Create, which will be significantly faster for this task.)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#deep_learning_model = graphlab.load_model('http://s3.amazonaws.com/GraphLab-Datasets/deeplearning/imagenet_model_iter45')\n", "#image_train['deep_features'] = deep_learning_model.extract_features(image_train)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
id | \n", "image | \n", "label | \n", "deep_features | \n", "image_array | \n", "
---|---|---|---|---|
24 | \n", "Height: 32 Width: 32 | \n", "bird | \n", "[0.242871761322, 1.09545373917, 0.0, ... | \n",
" [73.0, 77.0, 58.0, 71.0, 68.0, 50.0, 77.0, 69.0, ... | \n",
"
33 | \n", "Height: 32 Width: 32 | \n", "cat | \n", "[0.525087952614, 0.0, 0.0, 0.0, 0.0, 0.0, ... | \n",
" [7.0, 5.0, 8.0, 7.0, 5.0, 8.0, 5.0, 4.0, 6.0, 7.0, ... | \n",
"
36 | \n", "Height: 32 Width: 32 | \n", "cat | \n", "[0.566015958786, 0.0, 0.0, 0.0, 0.0, 0.0, ... | \n",
" [169.0, 122.0, 65.0, 131.0, 108.0, 75.0, ... | \n",
"
70 | \n", "Height: 32 Width: 32 | \n", "dog | \n", "[1.12979578972, 0.0, 0.0, 0.778194487095, 0.0, ... | \n",
" [154.0, 179.0, 152.0, 159.0, 183.0, 157.0, ... | \n",
"
90 | \n", "Height: 32 Width: 32 | \n", "bird | \n", "[1.71786928177, 0.0, 0.0, 0.0, 0.0, 0.0, ... | \n",
" [216.0, 195.0, 180.0, 201.0, 178.0, 160.0, ... | \n",
"
97 | \n", "Height: 32 Width: 32 | \n", "automobile | \n", "[1.57818555832, 0.0, 0.0, 0.0, 0.0, 0.0, ... | \n",
" [33.0, 44.0, 27.0, 29.0, 44.0, 31.0, 32.0, 45.0, ... | \n",
"
107 | \n", "Height: 32 Width: 32 | \n", "dog | \n", "[0.0, 0.0, 0.220677852631, 0.0, ... | \n",
" [97.0, 51.0, 31.0, 104.0, 58.0, 38.0, 107.0, 61.0, ... | \n",
"
121 | \n", "Height: 32 Width: 32 | \n", "bird | \n", "[0.0, 0.23753464222, 0.0, 0.0, 0.0, 0.0, ... | \n",
" [93.0, 96.0, 88.0, 102.0, 106.0, 97.0, 117.0, ... | \n",
"
136 | \n", "Height: 32 Width: 32 | \n", "automobile | \n", "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 7.5737862587, 0.0, ... | \n",
" [35.0, 59.0, 53.0, 36.0, 56.0, 56.0, 42.0, 62.0, ... | \n",
"
138 | \n", "Height: 32 Width: 32 | \n", "bird | \n", "[0.658935725689, 0.0, 0.0, 0.0, 0.0, 0.0, ... | \n",
" [205.0, 193.0, 195.0, 200.0, 187.0, 193.0, ... | \n",
"
query_label | \n", "reference_label | \n", "distance | \n", "rank | \n", "
---|---|---|---|
0 | \n", "384 | \n", "0.0 | \n", "1 | \n", "
0 | \n", "6910 | \n", "36.9403137951 | \n", "2 | \n", "
0 | \n", "39777 | \n", "38.4634888975 | \n", "3 | \n", "
0 | \n", "36870 | \n", "39.7559623119 | \n", "4 | \n", "
0 | \n", "41734 | \n", "39.7866014148 | \n", "5 | \n", "